<?php slot('sub', $sub); ?>

<div class="center">
    <div id="center_conteiner" class="clearfix">
        <div class="center_sub_conteiner">

            <div class="center_block">
                <div class="header_center_block">
                    <span>Add new Hotel</span>
                    <div class="back_button"><a href="<?php echo url_for('ahotels'); ?>">Back</a></div>
                </div>

                <div class="center_line" id="add_new_hotel_en">
                    <div class="field_label">Name in English</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line"  id="add_new_hotel_ru">
                    <div class="field_label">Name in Russian</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_hotel_he">
                    <div class="field_label">Name in Hebrew</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_hotel_stars">
                    <div class="field_label">Stars</div>
                    <div class="field_stars">
                        <ul>
                            <li value="1" selected="selected"><img src="../images/icoStar.png"></li>
                            <li value="2"><img src="../images/icoGreyStar.png"></li>
                            <li value="3"><img src="../images/icoGreyStar.png"></li>
                            <li value="4"><img src="../images/icoGreyStar.png"></li>
                            <li value="5"><img src="../images/icoGreyStar.png"></li>
                        </ul>
                    </div>
                </div>

                <div class="center_line" id="add_new_hotel_country">
                    <div class="field_label">Country</div>
                    <select class="field_select">
                        <option value="0">Select country</option>
                        <?php
                        foreach ($country as $c) {
                            echo "<option value='" . $c->getId() . "'>" . $c->getNameEn() . "</option>";
                        }
                        ?>
                    </select>
                </div>

                <div class="center_line" id="add_new_hotel_region">
                    <div class="field_label">Region</div>
                    <select class="field_select">

                    </select>
                </div>

                <div class="center_line" id="add_new_hotel_city">
                    <div class="field_label">City</div>
                    <select class="field_select"></select>
                </div>

                <script  type="text/javascript">
                    var regions = [];
                    var cites = [];
                    <?php foreach ($region as $r) { ?>
                        var temp = {
                            id: '<?php echo $r->getId() ?>',
                            nameEn: '<?php echo $r->getNameEn() ?>',
                            country_id: '<?php echo $r->getCountryId() ?>'
                        };

                        regions.push(temp);
                    <?php } ?>
                    
                    <?php foreach ($city as $c) { ?>
                        var temp = {
                            id: '<?php echo $c->getId() ?>',
                            nameEn: '<?php echo $c->getNameEn() ?>',
                            country_id: '<?php echo $c->getCountryId() ?>',
                            region_id: '<?php echo $c->getRegionId() ?>'
                        };

                        cites.push(temp);
                    <?php } ?>
                    
                    $(function () {
                        insertRegions(0);
                        insertCity(0, 0);
                        
                        var countryId = 0;
                        $('#add_new_hotel_country select').change(function() {
                            countryId = $(this).val();
                            insertRegions(countryId);
                            insertCity(countryId, 0);
                        });
                        
                        $('#add_new_hotel_region select').change(function() {
                            insertCity(countryId, $(this).val());
                        });
                    });
                    
                    function insertCity(country_id, region_id) {
                        $('#add_new_hotel_city select option').remove();
                        var parentSelect = $('#add_new_hotel_city select');
                        var firstOption = '<option value="0">Select city</option>';
                        (parentSelect).append(firstOption);

                        $.each(cites, function(i, v) {
                            if (country_id != 0 && region_id != 0) {
                                if (v.country_id == country_id && v.region_id == region_id) {
                                    (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                                }
                            } else if (country_id != 0 && region_id == 0) {
                                if (v.country_id == country_id) {
                                    (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                                }
                            } else if (country_id == 0 && region_id != 0) {
                                if (v.region_id == region_id) {
                                    (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                                }
                            } else if (country_id == 0 && region_id == 0) {
                                (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                            }
                        })
                    }
                    
                    function insertRegions(country_id) {
                        $('#add_new_hotel_region select option').remove();
                        var parentSelect = $('#add_new_hotel_region select');
                        var firstOption = $('<option value="0">Select region</option>');
                        (parentSelect).append(firstOption);

                        $.each(regions, function(i, v) {
                            if (country_id != 0) {
                                if (v.country_id == country_id) {
                                    (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                                }
                            } else {
                                (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                            }
                        });
                    }
                </script>
                
                <div class="center_line" id="add_new_hotel_provider">
                    <div class="field_label">Provider</div>
                    <select class="field_select">
                        <option value="0">Select provider</option>
                        <?php
                        foreach ($provider as $c) {
                            echo "<option value='" . $c->getId() . "'>" . $c->getShortName() . "</option>";
                        }
                        ?>
                    </select>
                </div>

                <div class="center_line" id="add_new_hotel_address">
                    <div class="field_label">Address</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_hotel_phone1">
                    <div class="field_label">Phone</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_hotel_phone2">
                    <div class="field_label">Phone</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_hotel_fax">
                    <div class="field_label">Fax</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_hotel_email">
                    <div class="field_label">E-mail</div>
                    <input type="text" class="field_input">
                </div>
                
                <div class="center_line" id="add_new_hotel_web">
                    <div class="field_label">Web Site</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line_large" id="add_new_hotel_descripton_en">
                    <div class="field_label">Description in English</div>
                    <textarea rows="5" cols="45" name="text" class="field_textarea" placeholder="text here..."></textarea>
                </div>

                <div class="center_line_large" id="add_new_hotel_descripton_ru">
                    <div class="field_label">Description in Russian</div>
                    <textarea rows="5" cols="45" name="text" class="field_textarea" placeholder="text here..."></textarea>
                </div>

                <div class="center_line_large" id="add_new_hotel_descripton_he">
                    <div class="field_label">Description in Hebrew</div>
                    <textarea rows="5" cols="45" name="text" class="field_textarea" placeholder="text here..."></textarea>
                </div>

                <div class="center_line_big" id="add_new_hotel_photo">
                    <div class="center_line_photo_add"></div>
                    <div class="photos_container"></div>
                </div>

                <div class="center_line" id="add_new_hotel_priority">
                    <div class="field_label">Priority</div>
                    <select class="field_select">
                        <option value="10">Very small</option>
                        <option value="20">Small</option>
                        <option value="30" selected="selected">Normal</option>
                        <option value="40">High</option>
                        <option value="50">Very high</option>
                    </select>
                </div>

                <div class="center_line">
                    <div class="field_button_positive" id="add_new_hotel_save">Save</div>
                    <div class="field_button_negative" id="add_new_hotel_cancel"><a href="<?php echo url_for('ahotels'); ?>">Cancel</a></div>
                </div>

            </div>
        </div>
    </div>
</div>

